﻿using System;
using System.Runtime.Serialization;

namespace Rogue
{
    [Serializable]
    public class Weapon : Entity
    {
        public Weapon(string a_Name, Attack a_Attack)
            : base(a_Name)
        {
            m_Attack = a_Attack;
            m_PickupLabel = -1; 
            Owner = null;
            
            m_IsAlive = false;      // is this weird? 
        }

        int m_PickupLabel;

        protected Entity m_Owner;
        public Entity Owner
        { 
            get { return m_Owner; }
            
            set 
            { 
                m_Owner = value;

                if (m_Owner != null)
                {
                    Position = m_Owner.Position;

                    if (m_PickupLabel != -1)
                    {
                        LabelHelper.Instance.Remove(m_PickupLabel); 
                        m_PickupLabel = -1;
                    }
                }

                if (m_Owner == null)
                {
                    Entity hero = RogueGame.Instance.Map.GetHero();
                    bool found = false;
                    foreach (Weapon weap in hero.Items)
                        if (weap.Name == Name)
                            found = true;

                    if (!found && m_PickupLabel == -1)
                    {
                        m_PickupLabel = LabelHelper.Instance.Add(Name, this);
                    }
                }
            } 
        }

        public override bool BlocksLight()
        {
            return false;
        }

        public override bool BlocksActor(Entity a_WantsToWalkThroughMe)
        {
            return false;
        }

        protected Attack m_Attack;
        public Attack GrantedAttack
        {
            get { return m_Attack; }
        }

        // what about non-weapon things? wands, potions, shields, armor, etc

        #region Serialization
        public Weapon(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
        }
        #endregion
    }
}